#include "favoritlinks.h"

#include <QWebEngineView>



FavoritLinks::FavoritLinks()
{
    add_link("AAA 猫猫侠 - 的博客", "https://blog.qinyn.eu.org/");
}

QString FavoritLinks::name()
{
    return "Favorit Link";
}

QList<QListWidgetItem *> FavoritLinks::searching_item(const QString &text)
{
    QList<QListWidgetItem *> list;
    foreach (auto favorit, m_favorits) {
        if (text.isEmpty() || favorit.contains(text, Qt::CaseInsensitive)) {
            auto item = newItem();
            item->setText(favorit);
            list << item;
        }
    }
    return list;
}

void FavoritLinks::content_item(const QListWidgetItem *item, QWebEngineView *view)
{
    view->load(m_favorit_links.value(item->text()));
}

void FavoritLinks::add_link(QString name, QString url)
{
    m_favorits << name;
    m_favorit_links.insert(name, url);
}
